﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace STLGROUP.Layers.Presentations.FormBase
{
    /// <summary>
    /// from main base
    /// </summary>
    /// <author>viet sang</author>
    public partial class frmMainMenuBase : frmBase
    {
        #region Constructors

        public frmMainMenuBase()
        {
            InitializeComponent();
        }

        #endregion
       
        #region Events

        private void btnClose_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void timer_Tick(object sender, EventArgs e)
        {
            lblTime.Text = DateTime.Now.ToString();
        }

        #endregion

        #region protected method

        protected void ShowChildForm(Form frm)
        {
            try
            {
                if (!CheckFormContained(frm.Name))
                {
                    
                    frm.MdiParent = this;
                    frm.Show();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Lỗi trong quá trình khởi động");
            }
        }

        protected void ShowChildFormHasPermission(frmManager frm)
        {
            try
            {
                if (!CheckFormContained(frm.Name))
                {
                    frm.PermissionForUser();

                    frm.MdiParent = this;
                    frm.Show();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Lỗi trong quá trình khởi động");
            }
        }

        protected void ShowDialogHasPermission(frmManager frm)
        {
            try
            {
                frm.PermissionForUser();
                frm.ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Lỗi trong quá trình khởi động");
            }
        }

        protected void ShowFromDialog(Form frm)
        {
            try
            {
                frm.ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Lỗi trong quá trình khởi động");
            }
        }

        private bool CheckFormContained(string frmName)
        {
            foreach (Form f in this.MdiChildren)
            {
                if (f.Name == frmName)
                    return true;
            }
            return false;
        }

        #endregion

    }
}
